/**
 * Created by Admin on 27.12.2014.
 */

(function ($) {

    $.format = function () {
        var s = arguments[0];
        for (var i = 0; i < arguments.length - 1; i++) {
            var reg = new RegExp("\\{" + i + "\\}", "gm");
            s = s.replace(reg, arguments[i + 1]);
        }

        return s;
    };

    Math.rescale = function (v, oldMin, oldMax, newMin, newMax) {
        return (v - oldMin) * (newMax - newMin) / (oldMax - oldMin);
    };

    Math.rescaleC = function (v, oldMin, oldMax, newMin, newMax) {
        var newV = Math.rescale(v, oldMin, oldMax, newMin, newMax);
        var left = newV < newMin;
        var right = newV > newMax;
        var fit = (!left) && (!right);
        return (fit && newV) || (left && newMin) || (right && newMax);
    };

    Math.degToRad = function(deg) {
        return deg * Math.PI / 180;
    };

})(window["jQuery"]);

